package cn.wjdiankong.levideo;

import java.lang.Thread.UncaughtExceptionHandler;

import android.content.Context;
import android.util.Log;
import cn.wjdiankong.levideo.activity.CrashLogActivity;

/** 
 * 自定义的 异常处理类 , 实现了 UncaughtExceptionHandler接口  
 */  
public class CrashHandler implements UncaughtExceptionHandler {  
    // 需求是 整个应用程序 只有一个 MyCrash-Handler   
    private static CrashHandler INSTANCE ;  
    private Context context;  
      
    //1.私有化构造方法  
    private CrashHandler(){  
    }  
      
    public static synchronized CrashHandler getInstance(){  
        if (INSTANCE == null)  
            INSTANCE = new CrashHandler();  
        return INSTANCE;
    }

    public void init(Context context){  
        this.context = context;
    }  
      
  
    public void uncaughtException(Thread arg0, Throwable arg1) {  
        CrashLogActivity.startDefault(context, Log.getStackTraceString(arg1));
    	//退出程序
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(1);
    }  

} 